/*  JEVEMon, A Java-based EVEMon clone.
    Copyright (C) 2011, Raul Ruiz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * JEVEMeView.java
 */

package jeveme;

import jeveme.datacontainers.*;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JFileChooser;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * The application's main frame.
 */
public class JEVEMeView extends FrameView {

    public JEVEMeView(SingleFrameApplication app) {
        super(app);

        initComponents();
                     
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        
        EVEMasterSkillSheet emss = EVEMasterSkillSheet.getInstance();
        
        
        //Setup the tabs.
        MasterDataContainer mdc = JEVEMeApp.getApplication().getMasterDataContainer();

       //Loop through all the characters and add tabs.
       ArrayList<EVEAccount> accounts = mdc.getAccounts();
       for(int i=0; i< accounts.size(); i++) {
            for(int j=0; j < accounts.get(i).getCharacters().size(); j++) {
                EVECharacter ec = accounts.get(i).getCharacters().get(j);
                if(ec.getTracked()) { //If we track this character, add a panel.
                    JEVEMeCharacterPanel char_panel = new JEVEMeCharacterPanel(ec);
                    mainTabbedPane.addTab(ec.getCharacterName(), char_panel);
                }
            }
       }
       mainTabbedPane.validate(); //Validate the Tabbed Panel
             
        //Update the Character Tabs
        updateCharacterTabs();     
        
        
        
        //Setup the timer to deal with updating the server's status and status bar label.
        updateServerStatusTimer  = new Timer(resourceMap.getInteger("ServerStatusUpdateFrequency"), new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                UpdateServerStatus uss = new UpdateServerStatus(serverStatusLabel);
                new Thread(uss).start();
            }
        }); 
        updateServerStatusTimer.setRepeats(true);
        updateServerStatusTimer.setInitialDelay(0);
        updateServerStatusTimer.start();
        
        //Setup the timer to update the EVE Time.
        updateEveTimeTimer = new Timer(60000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                UpdateEveTime uet = new UpdateEveTime(eveTimeLabel);
                new Thread(uet).start();
            }
        });
        updateEveTimeTimer.setRepeats(true);
        updateEveTimeTimer.setInitialDelay(0);
        updateEveTimeTimer.start();
        
        

    }
    
    /**
     * 
     */
    public final void updateCharacterTabs() {
        MasterDataContainer mdc = JEVEMeApp.getApplication().getMasterDataContainer();
        mainTabbedPane.removeAll();
        JEVEMeOverviewPanel overviewPanel = new JEVEMeOverviewPanel();
        mainTabbedPane.insertTab("Overview", null, overviewPanel, null, mainTabbedPane.getTabCount());
        
        ArrayList<EVEAccount> accounts = mdc.getAccounts();
        for(int i=0; i<accounts.size(); i++) {
            for(int j=0;j<accounts.get(i).getCharacters().size(); j++){
                EVECharacter ec = accounts.get(i).getCharacters().get(j);
                if(!ec.getTracked()) {
                    continue;
                }
                else {
                    JEVEMeCharacterPanel character_panel = new JEVEMeCharacterPanel(ec);
                    mainTabbedPane.insertTab(ec.getCharacterName(), null, character_panel, null, mainTabbedPane.getTabCount());
                }
            }
        }
        
        //Set the overview panel to be the selected tab.
        mainTabbedPane.setSelectedIndex(0);
    }
    
    
    
    
    
    
    
    @Action
    public void showMineralsWorksheet() {
        if(mineralWorksheetBox==null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            mineralWorksheetBox = new JEVEMeMineralWorksheetBox(mainFrame, false);
            mineralWorksheetBox.setLocationRelativeTo(mainFrame);
        }
        JEVEMeApp.getApplication().show(mineralWorksheetBox);
        
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            aboutBox = new JEVEMeAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        JEVEMeApp.getApplication().show(aboutBox);
    }
    
    @Action
    public void showOptionsDialogBox() {
        if(optionsDialogBox == null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            optionsDialogBox = new JEVEMeOptionsDialogBox(mainFrame, true);
            optionsDialogBox.setLocationRelativeTo(mainFrame);
        }
        JEVEMeApp.getApplication().show(optionsDialogBox);
    }
    
    @Action
    public void didPressOREChartMenuItem() {
        if(oreChartBox == null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            oreChartBox = new JEVEMeOREChartBox(mainFrame, false);
            oreChartBox.setLocationRelativeTo(mainFrame);
        }
        JEVEMeApp.getApplication().show(oreChartBox);
    }
    
    @Action
    public void didPressIceChartMenuItem() {
        if(iceChartBox == null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            iceChartBox = new JEVEMeIceChartBox(mainFrame, false);
            iceChartBox.setLocationRelativeTo(mainFrame);
        }
        JEVEMeApp.getApplication().show(iceChartBox);
    }
    
    @Action
    public void showAddAccountModal() {
        if (addAccountBox == null) {
            JFrame mainFrame = JEVEMeApp.getApplication().getMainFrame();
            addAccountBox = new JEVEMeAddAccountBox(mainFrame, true);
            addAccountBox.setLocationRelativeTo(mainFrame);
            
        }
        JEVEMeApp.getApplication().show(addAccountBox);
        updateCharacterTabs();
    }
    
    @Action
    public void didPressCopySkillsMenuItem() {
        SkillsToClipboard stc = new SkillsToClipboard();
        stc.CopySkillsToBBCodeAndClipboard();
    }
    
    @Action
    public void didPressForumMenuItem() {
        if( !java.awt.Desktop.isDesktopSupported() ) {
            return;
        }

        java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

        if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
             return;
        }
        try {

                java.net.URI uri = new java.net.URI( "http://forums.jeveme.com/" );
                desktop.browse( uri );
        }
        catch ( Exception e ) {}
        
        
    }
    
    @Action
    public void didPressSaveSettingsMenuItem() {
        //Create a file chooser
        final JFileChooser fc = new JFileChooser();

        //In response to a button click:
        int returnVal = fc.showOpenDialog(this.getComponent());
        
        File saveFile;
        
        if(returnVal == JFileChooser.APPROVE_OPTION)
        {
            saveFile = fc.getSelectedFile();
        }
        else {
            return;
        }
        return;
    }
    
    @Action
    public void didPressRestoreSettingsMenuItem() {
        //Create a file chooser
        final JFileChooser fc = new JFileChooser();

        //In response to a button click:
        int returnVal = fc.showOpenDialog(this.getComponent());
        
        File selectedFile;
        
        if(returnVal == JFileChooser.APPROVE_OPTION)
        {
            selectedFile = fc.getSelectedFile();
        }
        else {
            return;
        }
        return;
    }
    
    @Action
    public void didPressDonate() {
        if( !java.awt.Desktop.isDesktopSupported() ) {
            return;
        }

        java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

        if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
             return;
        }
        try {

                java.net.URI uri = new java.net.URI( "http://forums.jeveme.com/" );
                desktop.browse( uri );
        }
        catch ( Exception e ) {}
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        mainTabbedPane = new javax.swing.JTabbedPane();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        addAccountMenuItem = new javax.swing.JMenuItem();
        manageAccountsMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        hideCharacterMenuItem = new javax.swing.JMenuItem();
        deleteCharacterMenuItem = new javax.swing.JMenuItem();
        exportCharacterMenuItem = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        saveSettingsMenuItem = new javax.swing.JMenuItem();
        restoreSettingsMenuItem = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JPopupMenu.Separator();
        resetSettingsMenuItem = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JPopupMenu.Separator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        copySkillsMenuItem = new javax.swing.JMenuItem();
        plansMenu = new javax.swing.JMenu();
        newPlanMenuitem = new javax.swing.JMenuItem();
        loadPlanMenuItem = new javax.swing.JMenuItem();
        managePlanMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        toolsMenu = new javax.swing.JMenu();
        mineralsOresMenu = new javax.swing.JMenu();
        mineralWorksheetMenuItem = new javax.swing.JMenuItem();
        oreChartMenuItem = new javax.swing.JMenuItem();
        oreMineralCalculatorMenuItem = new javax.swing.JMenuItem();
        iceChartMenuItem = new javax.swing.JMenuItem();
        skillsPieChartMenuItem = new javax.swing.JMenuItem();
        schedulerMenuItem = new javax.swing.JMenuItem();
        blankCharacterCreatorMenuItem = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        implantGroupsMenuItem = new javax.swing.JMenuItem();
        showOwnedSkillbooksMenuItem = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        optionsMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        forumsMenuItem = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        serverStatusLabel = new javax.swing.JLabel();
        eveTimeLabel = new javax.swing.JLabel();

        mainPanel.setName("mainPanel"); // NOI18N

        mainTabbedPane.setName("mainTabbedPane"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1028, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jeveme.JEVEMeApp.class).getContext().getResourceMap(JEVEMeView.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jeveme.JEVEMeApp.class).getContext().getActionMap(JEVEMeView.class, this);
        addAccountMenuItem.setAction(actionMap.get("showAddAccountModal")); // NOI18N
        addAccountMenuItem.setIcon(resourceMap.getIcon("addAccountMenuItem.icon")); // NOI18N
        addAccountMenuItem.setText(resourceMap.getString("addAccountMenuItem.text")); // NOI18N
        addAccountMenuItem.setToolTipText(resourceMap.getString("addAccountMenuItem.toolTipText")); // NOI18N
        addAccountMenuItem.setName("addAccountMenuItem"); // NOI18N
        fileMenu.add(addAccountMenuItem);

        manageAccountsMenuItem.setIcon(resourceMap.getIcon("manageAccountsMenuItem.icon")); // NOI18N
        manageAccountsMenuItem.setText(resourceMap.getString("manageAccountsMenuItem.text")); // NOI18N
        manageAccountsMenuItem.setName("manageAccountsMenuItem"); // NOI18N
        fileMenu.add(manageAccountsMenuItem);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        hideCharacterMenuItem.setIcon(resourceMap.getIcon("hideCharacterMenuItem.icon")); // NOI18N
        hideCharacterMenuItem.setText(resourceMap.getString("hideCharacterMenuItem.text")); // NOI18N
        hideCharacterMenuItem.setName("hideCharacterMenuItem"); // NOI18N
        fileMenu.add(hideCharacterMenuItem);

        deleteCharacterMenuItem.setIcon(resourceMap.getIcon("deleteCharacterMenuItem.icon")); // NOI18N
        deleteCharacterMenuItem.setText(resourceMap.getString("deleteCharacterMenuItem.text")); // NOI18N
        deleteCharacterMenuItem.setName("deleteCharacterMenuItem"); // NOI18N
        fileMenu.add(deleteCharacterMenuItem);

        exportCharacterMenuItem.setIcon(resourceMap.getIcon("exportCharacterMenuItem.icon")); // NOI18N
        exportCharacterMenuItem.setText(resourceMap.getString("exportCharacterMenuItem.text")); // NOI18N
        exportCharacterMenuItem.setName("exportCharacterMenuItem"); // NOI18N
        fileMenu.add(exportCharacterMenuItem);

        jSeparator6.setName("jSeparator6"); // NOI18N
        fileMenu.add(jSeparator6);

        saveSettingsMenuItem.setAction(actionMap.get("didPressSaveSettingsMenuItem")); // NOI18N
        saveSettingsMenuItem.setIcon(resourceMap.getIcon("saveSettingsMenuItem.icon")); // NOI18N
        saveSettingsMenuItem.setText(resourceMap.getString("saveSettingsMenuItem.text")); // NOI18N
        saveSettingsMenuItem.setName("saveSettingsMenuItem"); // NOI18N
        fileMenu.add(saveSettingsMenuItem);

        restoreSettingsMenuItem.setAction(actionMap.get("didPressRestoreSettingsMenuItem")); // NOI18N
        restoreSettingsMenuItem.setIcon(resourceMap.getIcon("restoreSettingsMenuItem.icon")); // NOI18N
        restoreSettingsMenuItem.setText(resourceMap.getString("restoreSettingsMenuItem.text")); // NOI18N
        restoreSettingsMenuItem.setName("restoreSettingsMenuItem"); // NOI18N
        fileMenu.add(restoreSettingsMenuItem);

        jSeparator7.setName("jSeparator7"); // NOI18N
        fileMenu.add(jSeparator7);

        resetSettingsMenuItem.setIcon(resourceMap.getIcon("resetSettingsMenuItem.icon")); // NOI18N
        resetSettingsMenuItem.setText(resourceMap.getString("resetSettingsMenuItem.text")); // NOI18N
        resetSettingsMenuItem.setName("resetSettingsMenuItem"); // NOI18N
        fileMenu.add(resetSettingsMenuItem);

        jSeparator8.setName("jSeparator8"); // NOI18N
        fileMenu.add(jSeparator8);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setIcon(resourceMap.getIcon("exitMenuItem.icon")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText(resourceMap.getString("editMenu.text")); // NOI18N
        editMenu.setName("editMenu"); // NOI18N

        copySkillsMenuItem.setAction(actionMap.get("didPressCopySkillsMenuItem")); // NOI18N
        copySkillsMenuItem.setIcon(resourceMap.getIcon("copySkillsMenuItem.icon")); // NOI18N
        copySkillsMenuItem.setText(resourceMap.getString("copySkillsMenuItem.text")); // NOI18N
        copySkillsMenuItem.setName("copySkillsMenuItem"); // NOI18N
        editMenu.add(copySkillsMenuItem);

        menuBar.add(editMenu);

        plansMenu.setLabel(resourceMap.getString("plansMenu.label")); // NOI18N
        plansMenu.setName("plansMenu"); // NOI18N

        newPlanMenuitem.setIcon(resourceMap.getIcon("newPlanMenuitem.icon")); // NOI18N
        newPlanMenuitem.setText(resourceMap.getString("newPlanMenuitem.text")); // NOI18N
        newPlanMenuitem.setName("newPlanMenuitem"); // NOI18N
        plansMenu.add(newPlanMenuitem);

        loadPlanMenuItem.setIcon(resourceMap.getIcon("loadPlanMenuItem.icon")); // NOI18N
        loadPlanMenuItem.setText(resourceMap.getString("loadPlanMenuItem.text")); // NOI18N
        loadPlanMenuItem.setName("loadPlanMenuItem"); // NOI18N
        plansMenu.add(loadPlanMenuItem);

        managePlanMenuItem.setIcon(resourceMap.getIcon("managePlanMenuItem.icon")); // NOI18N
        managePlanMenuItem.setText(resourceMap.getString("managePlanMenuItem.text")); // NOI18N
        managePlanMenuItem.setName("managePlanMenuItem"); // NOI18N
        plansMenu.add(managePlanMenuItem);

        jSeparator2.setName("jSeparator2"); // NOI18N
        plansMenu.add(jSeparator2);

        menuBar.add(plansMenu);

        toolsMenu.setLabel(resourceMap.getString("toolsMenu.label")); // NOI18N
        toolsMenu.setName("toolsMenu"); // NOI18N

        mineralsOresMenu.setIcon(resourceMap.getIcon("mineralsOresMenu.icon")); // NOI18N
        mineralsOresMenu.setText(resourceMap.getString("mineralsOresMenu.text")); // NOI18N
        mineralsOresMenu.setName("mineralsOresMenu"); // NOI18N

        mineralWorksheetMenuItem.setAction(actionMap.get("showMineralsWorksheet")); // NOI18N
        mineralWorksheetMenuItem.setIcon(resourceMap.getIcon("mineralWorksheetMenuItem.icon")); // NOI18N
        mineralWorksheetMenuItem.setText(resourceMap.getString("mineralWorksheetMenuItem.text")); // NOI18N
        mineralWorksheetMenuItem.setName("mineralWorksheetMenuItem"); // NOI18N
        mineralsOresMenu.add(mineralWorksheetMenuItem);

        oreChartMenuItem.setAction(actionMap.get("didPressOREChartMenuItem")); // NOI18N
        oreChartMenuItem.setText(resourceMap.getString("oreChartMenuItem.text")); // NOI18N
        oreChartMenuItem.setName("oreChartMenuItem"); // NOI18N
        mineralsOresMenu.add(oreChartMenuItem);

        oreMineralCalculatorMenuItem.setText(resourceMap.getString("oreMineralCalculatorMenuItem.text")); // NOI18N
        oreMineralCalculatorMenuItem.setName("oreMineralCalculatorMenuItem"); // NOI18N
        mineralsOresMenu.add(oreMineralCalculatorMenuItem);

        iceChartMenuItem.setAction(actionMap.get("didPressIceChartMenuItem")); // NOI18N
        iceChartMenuItem.setText(resourceMap.getString("iceChartMenuItem.text")); // NOI18N
        iceChartMenuItem.setName("iceChartMenuItem"); // NOI18N
        mineralsOresMenu.add(iceChartMenuItem);

        toolsMenu.add(mineralsOresMenu);

        skillsPieChartMenuItem.setIcon(resourceMap.getIcon("skillsPieChartMenuItem.icon")); // NOI18N
        skillsPieChartMenuItem.setText(resourceMap.getString("skillsPieChartMenuItem.text")); // NOI18N
        skillsPieChartMenuItem.setName("skillsPieChartMenuItem"); // NOI18N
        toolsMenu.add(skillsPieChartMenuItem);

        schedulerMenuItem.setIcon(resourceMap.getIcon("schedulerMenuItem.icon")); // NOI18N
        schedulerMenuItem.setText(resourceMap.getString("schedulerMenuItem.text")); // NOI18N
        schedulerMenuItem.setName("schedulerMenuItem"); // NOI18N
        toolsMenu.add(schedulerMenuItem);

        blankCharacterCreatorMenuItem.setText(resourceMap.getString("blankCharacterCreatorMenuItem.text")); // NOI18N
        blankCharacterCreatorMenuItem.setName("blankCharacterCreatorMenuItem"); // NOI18N
        toolsMenu.add(blankCharacterCreatorMenuItem);

        jSeparator3.setName("jSeparator3"); // NOI18N
        toolsMenu.add(jSeparator3);

        implantGroupsMenuItem.setIcon(resourceMap.getIcon("implantGroupsMenuItem.icon")); // NOI18N
        implantGroupsMenuItem.setText(resourceMap.getString("implantGroupsMenuItem.text")); // NOI18N
        implantGroupsMenuItem.setName("implantGroupsMenuItem"); // NOI18N
        toolsMenu.add(implantGroupsMenuItem);

        showOwnedSkillbooksMenuItem.setIcon(resourceMap.getIcon("showOwnedSkillbooksMenuItem.icon")); // NOI18N
        showOwnedSkillbooksMenuItem.setText(resourceMap.getString("showOwnedSkillbooksMenuItem.text")); // NOI18N
        showOwnedSkillbooksMenuItem.setName("showOwnedSkillbooksMenuItem"); // NOI18N
        toolsMenu.add(showOwnedSkillbooksMenuItem);

        jSeparator4.setName("jSeparator4"); // NOI18N
        toolsMenu.add(jSeparator4);

        optionsMenuItem.setAction(actionMap.get("showOptionsDialogBox")); // NOI18N
        optionsMenuItem.setIcon(resourceMap.getIcon("optionsMenuItem.icon")); // NOI18N
        optionsMenuItem.setText(resourceMap.getString("optionsMenuItem.text")); // NOI18N
        optionsMenuItem.setName("optionsMenuItem"); // NOI18N
        toolsMenu.add(optionsMenuItem);

        menuBar.add(toolsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        forumsMenuItem.setAction(actionMap.get("didPressForumMenuItem")); // NOI18N
        forumsMenuItem.setIcon(resourceMap.getIcon("forumsMenuItem.icon")); // NOI18N
        forumsMenuItem.setText(resourceMap.getString("forumsMenuItem.text")); // NOI18N
        forumsMenuItem.setName("forumsMenuItem"); // NOI18N
        helpMenu.add(forumsMenuItem);

        jMenuItem1.setAction(actionMap.get("didPressDonate")); // NOI18N
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        helpMenu.add(jMenuItem1);

        jSeparator5.setName("jSeparator5"); // NOI18N
        helpMenu.add(jSeparator5);

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setIcon(resourceMap.getIcon("aboutMenuItem.icon")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        serverStatusLabel.setText(resourceMap.getString("serverStatusLabel.text")); // NOI18N
        serverStatusLabel.setName("serverStatusLabel"); // NOI18N

        eveTimeLabel.setText(resourceMap.getString("eveTimeLabel.text")); // NOI18N
        eveTimeLabel.setName("eveTimeLabel"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1028, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(eveTimeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(serverStatusLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 588, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(statusMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(statusAnimationLabel)
                            .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(3, 3, 3))
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(eveTimeLabel)
                        .addComponent(serverStatusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem addAccountMenuItem;
    private javax.swing.JMenuItem blankCharacterCreatorMenuItem;
    private javax.swing.JMenuItem copySkillsMenuItem;
    private javax.swing.JMenuItem deleteCharacterMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JLabel eveTimeLabel;
    private javax.swing.JMenuItem exportCharacterMenuItem;
    private javax.swing.JMenuItem forumsMenuItem;
    private javax.swing.JMenuItem hideCharacterMenuItem;
    private javax.swing.JMenuItem iceChartMenuItem;
    private javax.swing.JMenuItem implantGroupsMenuItem;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JPopupMenu.Separator jSeparator7;
    private javax.swing.JPopupMenu.Separator jSeparator8;
    private javax.swing.JMenuItem loadPlanMenuItem;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTabbedPane mainTabbedPane;
    private javax.swing.JMenuItem manageAccountsMenuItem;
    private javax.swing.JMenuItem managePlanMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem mineralWorksheetMenuItem;
    private javax.swing.JMenu mineralsOresMenu;
    private javax.swing.JMenuItem newPlanMenuitem;
    private javax.swing.JMenuItem optionsMenuItem;
    private javax.swing.JMenuItem oreChartMenuItem;
    private javax.swing.JMenuItem oreMineralCalculatorMenuItem;
    private javax.swing.JMenu plansMenu;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JMenuItem resetSettingsMenuItem;
    private javax.swing.JMenuItem restoreSettingsMenuItem;
    private javax.swing.JMenuItem saveSettingsMenuItem;
    private javax.swing.JMenuItem schedulerMenuItem;
    private javax.swing.JLabel serverStatusLabel;
    private javax.swing.JMenuItem showOwnedSkillbooksMenuItem;
    private javax.swing.JMenuItem skillsPieChartMenuItem;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JMenu toolsMenu;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Timer updateServerStatusTimer;
    private final Timer updateEveTimeTimer;
    
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private JDialog addAccountBox;
    private JDialog optionsDialogBox;
    private JDialog mineralWorksheetBox;
    private JDialog oreChartBox;
    private JDialog iceChartBox;
}
